//
//  MemberWelfareChoiceContentTableViewCell.m
//  quxiangtao
//
//  Created by xbmios on 2018/7/30.
//  Copyright © 2018年 shanhaijin. All rights reserved.
//

#import "MemberWelfareChoiceContentTableViewCell.h"

@interface MemberWelfareChoiceContentTableViewCell ()

@property (strong, nonatomic) UIView *bgView;
@property (strong, nonatomic) UIImageView *rankIV;
@property (strong, nonatomic) UIImageView *goodIV;
@property (strong, nonatomic) UILabel *goodNameL;
@property (strong, nonatomic) UILabel *priceL;

@end

@implementation MemberWelfareChoiceContentTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        
        [self.contentView addSubview:self.bgView];
        [self.contentView addSubview:self.goodIV];
        [self.contentView addSubview:self.goodNameL];
        [self.contentView addSubview:self.priceL];
        [self.contentView addSubview:self.rankIV];
    }
    
    return self;
}

- (void)setGoodListModel:(SupportCategoryGoodListModel *)goodListModel {
    NSString *urlString = @"";
    if ([goodListModel.goods_url hasPrefix:@"http://"] || [goodListModel.goods_url hasPrefix:@"https://"]) {
        urlString = goodListModel.goods_url;
    }else {
        urlString = [NSString stringWithFormat:@"http://%@",goodListModel.goods_url];
    }
    [self.goodIV sd_setImageWithURL:[NSURL URLWithString:urlString]];
    self.goodNameL.text = goodListModel.title;
    self.priceL.text = [NSString stringWithFormat:@"%.2f",[goodListModel.price floatValue] - [goodListModel.dintegral floatValue]];
}

- (void)setType:(NSInteger)type {
    
    _type = type;
    
    if (type == 0) {
        
        self.rankIV.hidden = NO;
        self.rankIV.image = [UIImage imageNamed:@"welfareFirstRankBG"];
        
    }else if (type == 1) {
        
        self.rankIV.hidden = NO;
        self.rankIV.image = [UIImage imageNamed:@"welfareSecondRankBG"];
        
    }else if (type == 2) {
        
        self.rankIV.hidden = NO;
         self.rankIV.image = [UIImage imageNamed:@"welfareThirdRankBG"];
        
    }else {
        
        self.rankIV.hidden = YES;
    }
}


- (void)layoutSubviews {
    
    [super layoutSubviews];
    
    __weak typeof(self) weakSelf = self;
    [self.bgView mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.centerX.mas_equalTo(weakSelf.contentView.mas_centerX);
        make.centerY.mas_equalTo(weakSelf.contentView.mas_centerY);
        make.width.mas_equalTo(jisuan(670));
        make.height.mas_equalTo(jisuan(200));
    }];
    [self.rankIV mas_makeConstraints:^(MASConstraintMaker *make) {
        
        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(20));
        make.top.mas_equalTo(weakSelf.contentView.mas_top).with.offset(jisuan(20));
        make.width.mas_equalTo(jisuan(50));
        make.height.mas_equalTo(jisuan(68));
    }];
    [self.goodIV mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left);
        make.top.mas_equalTo(weakSelf.contentView.mas_top);
        make.bottom.mas_equalTo(weakSelf.contentView.mas_bottom);
        make.width.mas_equalTo(jisuan(200));
    }];
    [self.goodNameL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(218));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(20));
        make.top.mas_equalTo(weakSelf.bgView.mas_top).with.offset(jisuan(28));

    }];
    [self.priceL mas_makeConstraints:^(MASConstraintMaker *make) {

        make.left.mas_equalTo(weakSelf.contentView.mas_left).with.offset(jisuan(218));
        make.right.mas_equalTo(weakSelf.contentView.mas_right).with.offset(-jisuan(20));
        make.bottom.mas_equalTo(weakSelf.bgView.mas_bottom).with.offset(-jisuan(20));

    }];

    
}

#pragma mark -lazy
- (UIView *)bgView {
    
    if (!_bgView) {
        
        _bgView = [[UIView alloc] init];
        _bgView.backgroundColor = WhiteColor;
        _bgView.layer.cornerRadius = jisuan(10);
        _bgView.layer.shadowColor = Colorefefef.CGColor;
        _bgView.layer.shadowOffset = CGSizeMake(0, 0);
        _bgView.layer.shadowOpacity = 0.5;
        _bgView.layer.shadowRadius = jisuan(5);
        
    }
    
    return _bgView;
}

- (UIImageView *)rankIV {
    
    if (!_rankIV) {
        
        _rankIV = [[UIImageView alloc] init];
        _rankIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _rankIV;
}
- (UIImageView *)goodIV {
    
    if (!_goodIV) {
        
        _goodIV = [[UIImageView alloc] init];
        _goodIV.contentMode = UIViewContentModeScaleAspectFit;
        
    }
    
    return _goodIV;
}

- (UILabel *)goodNameL {
    
    if (!_goodNameL) {
        
        _goodNameL = [[UILabel alloc] init];
        _goodNameL.textColor = Color333333;
        _goodNameL.font = Font(24);
        _goodNameL.numberOfLines = 2;
        
        NSString *str = @"LeBron XV EP 男子篮球鞋搭载新版设计与强大的缓震系统组合。";
        
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        NSMutableParagraphStyle *paragraphStyle = [[NSMutableParagraphStyle alloc] init];
        paragraphStyle.lineSpacing = jisuan(3);
        [attributeStr addAttribute:NSParagraphStyleAttributeName value:paragraphStyle range:NSMakeRange(0, str.length)];
        _goodNameL.attributedText = attributeStr;
        
        _goodNameL.textAlignment = NSTextAlignmentLeft;
        
    }
    
    return _goodNameL;
    
}
- (UILabel *)priceL {
    
    if (!_priceL) {
        
        _priceL = [[UILabel alloc] init];
        _priceL.textColor = Color333333;
        //        _priceL.textColor = Color333333;
        _priceL.textAlignment = NSTextAlignmentLeft;
        
        NSString *str = @"￥ 949.00";
        NSMutableAttributedString *attributeStr = [[NSMutableAttributedString alloc] initWithString:str];
        [attributeStr addAttribute:NSFontAttributeName value:Font(20) range:NSMakeRange(0, 1)];
        [attributeStr addAttribute:NSFontAttributeName value:Font(40) range:NSMakeRange(1, str.length - 1)];
        _priceL.attributedText = attributeStr;
        
    }
    
    return _priceL;
    
}

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

@end
